<?php
	/*
	 * This file is part of phpitter.
 	 * 
	 * phpitter is free software: you can redistribute it and/or modify
	 * it under the terms of the GNU General Public License as published by
	 * the Free Software Foundation, either version 3 of the License, or
	 * (at your option) any later version.
 	 * 
	 * phpitter is distributed in the hope that it will be useful,
	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	 * GNU General Public License for more details.
 	 * 
	 * You should have received a copy of the GNU General Public License
	 * along with phpitter.  If not, see <http://www.gnu.org/licenses/>.
	 *
	 * Copyright 2008 Ryan Hadley
	 */

	class PhpitterPluggable
	{
		var $entryChangeCallbacks = array();
		var $entrySubmitCallbacks = array();
		var $newUpdatesCallbacks = array();
		var $displayTweetCallbacks = array();

		function registerEntryChangeCallback($function)
		{
			$this->entryChangeCallbacks[] = $function;
		}

		function changedEntryBox($entryBox)
		{
			foreach ( $this->entryChangeCallbacks as $pluginFunction )
			{
				$pluginFunction($entryBox);
			}
		}

		function registerEntrySubmitCallback($function)
		{
			$this->entrySubmitCallbacks[] = $function;
		}

		function registerNewUpdatesCallback($function)
		{
			$this->newUpdatesCallbacks[] = $function;
		}

		function submittedEntryBox($entryBox)
		{
			foreach ( $this->entrySubmitCallbacks as $pluginFunction )
			{
				$pluginFunction($entryBox);
			}
		}

		function newUpdates($updates)
		{
			if ( ! is_array($updates) )
				return false;
			foreach ( $this->newUpdatesCallbacks as $pluginFunction )
			{
				$pluginFunction($updates);
			}
		}

		function registerDisplayTweetCallback($function)
		{
			$this->displayTweetCallbacks[] = $function;
		}

		function displayTweet($tweetText)
		{
			foreach ( $this->displayTweetCallbacks as $pluginFunction )
			{
				$tweetText = $pluginFunction($tweetText);
			}
			return $tweetText;
		}
	}
?>
